<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/7/31 0031
 * Time: 下午 3:57
 */

namespace app\model;
class SchoolStudent extends \think\Model{
  public $table="school_student";


    /**
     * 保存学生资料
     * @param $data
     * @return $this|int|string
     */
    function save_student($data){
        $user_id=$data['user_id'];
        $o=$this->where(['user_id'=>$user_id])->column("id");


        $data2['stu_name']=$data['stu_name'];
        $data2['edu_type']=$data['edu_type'];
        $data2['department_name']=$data['department_name'];
        $data2['major']=$data['major'];
        $data2['enter_school_time']=$data['enter_school_time'];
        $data2['school_id']=$data['school_id'];

        if($o[0]!=false){

            $data2['updated_at']=cur_time();
           return  $this->where(['user_id'=>$user_id])->update($data2);
        }else{

            $data2['user_id']=$user_id;
            $data2['created_at']=cur_time();
            return $this->insertGetId($data2);
        }


    }

    /**
     * 根据用户ID,返回学生卡信息
     * @param $user_id
     * @return mixed
     */
    function get_student($user_id){
        $o=$this->where(['user_id'=>$user_id])->find();
        $arr=object2array($o);

        if($arr!=false){
            $School=new School();
            $arr['school_id_name']=$School->get_school_name_by_id($arr['school_id']);
            $arr['edu_type_name']=config("web.school_edu_type")[$arr['edu_type']];
        }
        return $arr;
    }


    function get_school_id_by_user_id($user_id){
        $o=$this->where(['user_id'=>$user_id])->column('school_id');
        if($o[0]){
            return $o[0];
        }else{
            return '';
        }
    }


}